import { getAdminInfoApi } from "@/apis/adminApi"
import { findStaffApi } from "@/apis/staffApi";
import { setAdminInfo } from "@/store/slices/admin";
import { setStaffData } from "@/store/slices/staff";
import { useDispatch } from "react-redux"

export const useSliceData = () => {

    const dispatch = useDispatch();

    // 获取登录用户数据
    const getAdminInfoHook = () => {
        getAdminInfoApi()
            .then(res => {
                if (res.code == 200) {
                    // dispatch调用状态机的公共方法，保存到到状态机
                    dispatch(setAdminInfo(res.data));
                }
            })
    }

    // 获取员工数据
    const getStaffHook = () => {
        findStaffApi()
            .then(res => {
                if(res.code == 200) {
                    dispatch(setStaffData(res.data))
                }
            })
    }

    return {
        getAdminInfoHook, getStaffHook
    }

}